# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Timothy Redaelli <timothy.redaelli@gmail.com>
# Contributor: fauno <fauno@parabola.nu>

pkgname=miniupnpd
pkgver=2.3.3
pkgrel=1
pkgdesc='Lightweight UPnP IGD daemon'
url='https://miniupnp.tuxfamily.org/'
arch=('loong64' 'x86_64')
license=('BSD')
backup=('etc/miniupnpd/miniupnpd.conf')
depends=('iptables' 'net-tools' 'util-linux' 'util-linux-libs' libuuid.so 'libcap-ng' libcap-ng.so)
makedepends=('lsb-release' 'procps-ng')
source=(https://miniupnp.tuxfamily.org/files/${pkgname}-${pkgver}.tar.gz{,.sig}
        miniupnpd.service)
sha512sums=('98915e3c1410d6753a58133596bad012fea205f36ae4991c2cf4b358d1e905e029287cfcf1aa97283c2e3c1cb8c20655bff35d49a37ae8756739e33c4ae3e7ef'
            'SKIP'
            '6387f646d91257e50159f66c5168830c5c845e1de739e52cc86647baafaa96ed3a5d00b6c7e46080c3dd998a486d81183c3c11ce9bf32e2f6d9fdd40b0ea8bef')
b2sums=('4b32e05bc7002bc7edc946f01b1984f3d184e0e9949a9685ffa5351ece9dacc09dc48567cc6f68972343a1921f4ceb5c541d4b557c4991f311289a511c492efa'
        'SKIP'
        '3db5bae2f4624f436a509dfda79183468b7d2112b5351b70f972319f3223722b1d2b5ac44516bb8f76995f04af0bb76b1e3a19e9afe011f5b104aae5f2058638')
validpgpkeys=(
  '751E9FF6944A3B36A5432216DB511043A31ACAAF' # miniupnp (miniupnp !) <miniupnp@free.fr>
)

prepare() {
  cd ${pkgname}-${pkgver}
  sed '/gzip/d' -i Makefile.linux
  sed 's|/sbin/sysctl|sysctl|g' -i configure
}

build() {
  cd ${pkgname}-${pkgver}
  ./configure \
    --ipv6 \
    --leasefile
  CONFIG_OPTIONS="--ipv6 --leasefile" make -f Makefile.linux config.h
  make -f Makefile.linux
}

package() {
  cd ${pkgname}-${pkgver}

  make DESTDIR="${pkgdir}" PREFIX=/ INSTALLPREFIX=/usr SBININSTALLDIR=/usr/bin -f Makefile.linux install

  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -Dm 644 ../miniupnpd.service -t "${pkgdir}/usr/lib/systemd/system"

  sed -i 's:/s\?bin/iptables:/usr/bin/iptables:
          s:eth0:"`cat /etc/miniupnpd/miniupnpd.conf | '"awk -F= '/^ext_ifname/ { print \$2 }'"'`":' "${pkgdir}"/etc/miniupnpd/*.sh
  sed -i -e "s/^uuid=[-0-9a-f]*/uuid=00000000-0000-0000-0000-000000000000/
             s/make genuuid/uuidgen/" "${pkgdir}/etc/miniupnpd/miniupnpd.conf"

  rm -r "${pkgdir}/etc/init.d"
}

# vim: ts=2 sw=2 et:
